package com.atguigu.gmall.oauth.service.impl;

import com.atguigu.gmall.common.execption.GmallException;
import com.atguigu.gmall.model.user.UserInfo;
import com.atguigu.gmall.oauth.mapper.UserInfoMapper;
import com.atguigu.gmall.oauth.service.UserInfoService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Map;

/***
 * 用户信息表service层接口的实现类
 */
@Service
public class UserInfoServiceImpl implements UserInfoService {

    @Autowired
    private UserInfoMapper userInfoMapper;

    /**
     * 保存用户信息
     *
     * @param userInfoMap
     */
    @Override
    public void save(Map<String, String> userInfoMap) {
        //获取用户的信息
        String username = userInfoMap.get("username");
        String password = userInfoMap.get("password");
        String phoneNum = userInfoMap.get("phoneNum");

        //1 判断用户名是否被注册
        UserInfo userInfo = userInfoMapper.selectOne(new LambdaQueryWrapper<UserInfo>().eq(UserInfo::getName, username));
        if(userInfo != null){
            //不为空，说明被注册
            throw new GmallException("用户名已被注册",null);
        }

        //3 发送短信

        //4 将数据保存到数据库

    }
}
